package cn.itcast.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyException implements HandlerExceptionResolver{


    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        ModelAndView modelAndView = new ModelAndView();
        if(ex instanceof UnauthorizedException){
            modelAndView.setViewName("forward:/unauthorized.jsp");
            return modelAndView;
        }

        modelAndView.addObject("msg","发生了错误，请耐心等待..");
        modelAndView.setViewName("error");
        return modelAndView;
    }
}
